PROJECT = "PROJECT"
VERSION = "1.0.0"
sys = require("sys")
 
-- 配置马达输出引脚为输出模式
gpio.setup(7, 1)

gpio.setup(18, 1)

-- 配置uart引脚
uart.setup(1, 9600)
uart.on(1, "receive", function()
    local val = uart.read(1)
    print("蓝牙收到了信息值：", val)
    motor_control(val)
end)
 
-- 马达控制函数
function motor_control(order)
  if (order == '1') then
    gpio.setup(7, 1)
  else
    gpio.setup(7, 0)  
  end
  uart.write(1, order)
end

sys.taskInit(function()
    while 1 do
        gpio.setup(18, 0)
        sys.wait(1000)
        gpio.setup(18, 1)
        sys.wait(1000)
    end
end)
 
sys.run()